package com.hrzyit.whistle.comm.data.repository

import com.hrzyit.base.data.net.RetrofitFactory
import com.hrzyit.base.data.protocol.BaseResp
import com.hrzyit.whistle.comm.data.api.ContactCenterApi
import com.hrzyit.whistle.comm.data.bean.ContactEntity
import com.hrzyit.whistle.comm.data.bean.DepartmentEntity
import com.hrzyit.whistle.comm.data.protocol.ContactByDeptUserReq
import com.hrzyit.whistle.comm.data.protocol.ContactByUserDetailReq
import com.hrzyit.whistle.comm.data.protocol.ContactListSearchListReq
import io.reactivex.Observable
import javax.inject.Inject

/**
 * 通讯录联络单位、联络人服务数据操作类
 * @author YangWei
 * @date 2019/5/6
 */
class ContactCenterRepository @Inject constructor() {

    /**
     * 通讯录-单位列表
     * @author YangWei
     * @date 2019/5/6
     * @return 单位列表 {@link DepartmentEntity}
     */
    fun selectContactDeptList(userId:Long): Observable<BaseResp<MutableList<DepartmentEntity>>> {
        val req = ContactListSearchListReq()
        req.userId = userId
        return RetrofitFactory.instance
            .create(ContactCenterApi::class.java)
            .selectContactDeptList(
                req
            )
    }

    /**
     * 通讯录-获取单位人员列表
     * @author YangWei
     * @date 2019/5/6
     * @param deptId    单位id
     * @return 获取单位人员列表{@link ContactEntity}
     */
    fun selectContactsList(deptId: Long): Observable<BaseResp<MutableList<ContactEntity>>> {
        val req = ContactByDeptUserReq()
        req.deptId = deptId

        return RetrofitFactory.instance
            .create(ContactCenterApi::class.java)
            .selectContactsList(
                req
            )
    }

    /**
     * 通讯录-获取单位人员列表
     * @author YangWei
     * @date 2019/5/6
     * @param deptId    单位id
     * @return 获取单位人员列表{@link ContactEntity}
     */
    fun getContactUserDetail(userId: Long): Observable<BaseResp<ContactEntity>> {
        val req = ContactByUserDetailReq(userId)
        return RetrofitFactory.instance
            .create(ContactCenterApi::class.java)
            .getContactUserDetail(
                req
            )
    }
}